package com.bradz.mytv;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;

import android.util.Log;

public class classCommercialParser {
	private String name;
	private boolean has_watched;
    private ArrayList<String> youtubeList = new ArrayList<String>();
	//http://www.reddit.com/r/videos+music/.json?sort=rising&limit=100
    classCommercialParser(classCommercialParser parse){
    	if(!parse.get_list().isEmpty()){
    		this.youtubeList = new ArrayList<String>(parse.get_list());
    	}
    	this.name = parse.name;
    	this.has_watched = parse.has_watched;
    }
    
	classCommercialParser(String json_feed){
		// Creating JSON Parser instance
		classJSONParser jParser = new classJSONParser();
		 
		// getting JSON string from URL
		JSONObject json = jParser.getJSONfromURL(json_feed);
		
		// Getting Array of Contacts
		Log.i("myTV - commercial_parser", "JSON: " + json.toString());
		Matcher m = Pattern.compile("\"url\":\".*?\"").matcher(json.toString());
		while (m.find()) {
			if((m.group()).indexOf("youtube") != -1){
				Log.i("myTV - commercial_parser", "Data: " + (m.group()).replace("\"url\":\"","").replace("\"", ""));
				youtubeList.add((m.group()).replace("\"url\":\"","").replace("\"", ""));
			}
		}
		Log.i("myTV - commercial_parser", "Data Found!");
	}
	
	public ArrayList<String> get_list(){
		return youtubeList;
	}
	
	public void print_list(){
		Log.i("myTV - networkHolder", "Printing List");
		for(int i = 0; i<youtubeList.size();i++){
			Log.i("myTV - commercial_parser", "Site Url: " + youtubeList.get(i));
		}
	}
}
